package com.itsu.spbspider.service.impl;

import com.alibaba.fastjson.JSON;
import com.itsu.spbspider.entity.source.SourceVideoObj;
import com.itsu.spbspider.exception.SystemException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author suben
 * @create time 2020/2/11 19:44
 */
@Service
public class BudejieVideoParse {

    public Map parseObj(String content) throws Exception {
        if (StringUtils.isBlank(content)) {
            return null;
        }

        Map map = null;
        try {
            map = new HashMap();
            List<Map> list = new ArrayList<>();
            SourceVideoObj sourceVideoObj = JSON.parseObject(content).toJavaObject(SourceVideoObj.class);
            for (SourceVideoObj.ListBean listBean : sourceVideoObj.getList()) {
                Map bean = new HashMap();
                bean.put("text", listBean.getText());
                bean.put("cate", listBean.getCate());
                bean.put("passtime", listBean.getPasstime());
                bean.put("playcount", listBean.getVideo() == null ? "" : listBean.getVideo().getPlaycount());
                bean.put("videoUrl", listBean.getVideo().getVideo().get(0));
                bean.put("image", listBean.getVideo().getThumbnail().get(0));
                list.add(bean);
            }
            map.put("data", list);
        } catch (Exception e) {
            throw new SystemException(e);
        }
        return map;
    }
}
